package hypeerweb;

import java.util.TreeMap;

public class Parameters {

	private TreeMap<String, Object> parameters;

	public Parameters() {
		parameters = new TreeMap<String, Object>();
	}

	/**
	 * @param key
	 * @return
	 * @pre None
	 * @post there exists k, v ((k, v) are elements of parameters AND k = key) implies result = v) ELSE result = null
	 */
	public Object get(String key) {
		if (parameters.containsKey(key)) {
			return parameters.get(key);
		} else {
			return null;
		}
	}

	/**
	 * Returns true or false depending on whether or not there exists a key-value pair with the given key. Parameters: key - the key we are searching for.
	 * 
	 * @pre None
	 * @post result = there exists k, object ((k, object) is an element of parameters AND k = key) -- The object may be null.
	 */
	public boolean containsKey(String key) {
		return parameters.containsKey(key);
	}

	/**
	 * @param key
	 * @param value
	 *            Inserts the key-value pair (key, value) into the parameters. If there was a key-value pair with the given key, it is removed from the parameters before inserting the new key-value
	 *            pair. The value may be null.
	 * @pre key != null
	 * @post (key, value) is an element of parameters
	 */
	public void set(String key, Object value) {
		parameters.put(key, value);
	}

}
